import { http } from "@/plugin/http";

// 获取battles列表
export const getBattlesList = async (params: API.Battles.BattleListParams) => {
  try {
    return await http.post<API.Battles.BattleListResponse>(
      "/battle/list",
      params
    );
  } catch (error) {
    return null;
  }
};

// 获取battles列表
export const joinBattle = async (params: API.Battles.JoinBattleParams) => {
  try {
    return await http.post<API.Battles.UserJoinResponse>(
      "/battle/user-join",
      params
    );
  } catch (error) {
    return null;
  }
};

// battle创建相同的对局
export const createCommonBattle = async (
  params: API.Battles.JoinBattleParams
) => {
  try {
    return await http.post<API.Battles.UserJoinResponse>(
      "/battle/recreate",
      params
    );
  } catch (error) {
    return null;
  }
};

// 详情
export const battleDetail = async (params: API.Battles.BattleDetailParams) => {
  try {
    return await http.post<API.Battles.BattleDetailResponse>(
      "/battle/detail",
      params
    );
  } catch (error) {
    return null;
  }
};

// 详情
export const createBattle = async (params: API.Battles.CreateBattleParams) => {
  try {
    return await http.post<API.Battles.JoinBattleParams>(
      "/battle/create",
      params
    );
  } catch (error) {
    return null;
  }
};

// battle添加机器人
export const createBot = async (params: API.Battles.CreateBotParams) => {
  try {
    await http.post("/battle/add-bot", params);
    return true;
  } catch (error) {
    return false;
  }
};
